package servlet;

import service.BookService;
import service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 李主席
 * @create 2020-11-10 14:55
 */
public class DelAllBooks  extends HttpServlet{

    private BookService bookService=new BookServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html");
        resp.setCharacterEncoding("UTF-8");
        String[] bookIds = req.getParameterValues("bookId");
        List<Integer> list=new ArrayList<>();
        for (String  bookId : bookIds){
      list.add(Integer.parseInt(bookId));
        }
          bookService.delAllBooks(list);
        resp.sendRedirect("/all_books");

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
